<?php
# 导入数据库接口文件
require_once 'dr-app-config.php';
require_once 'dr-app-functions.php';

require_once 'dr-db-pages.php';

# 获得用户的请求
$action = isset($_POST['action']) ? $_POST['action'] : '';
//$action = 'get_general_settings';
switch ($action) {
	case 'get_all_pages_without_content':
		echo dr_get_all_pages_without_content();
		break;

	case 'get_page_with_id':
		echo dr_get_page_with_id();
		break;

	case 'add_page':
		echo dr_add_page();
		break;

	case 'update_page':
		echo dr_update_page();
		break;

	default:
		echo '';
}

function dr_get_all_pages_without_content()
{
	$result = dr_db_get_all_pages_without_content();
	return json_encode($result);
}

function dr_get_page_with_id()
{
	$page_id = $_POST['page_id'];

	$result = dr_db_get_page_with_id($page_id);
	return json_encode($result);
}

function dr_add_page()
{
	$page = json_decode($_POST['page'], true);

	$result = dr_db_add_page($page);
	return $result;
}

function dr_update_page()
{
	$page = json_decode($_POST['page'], true);

	$result = dr_db_update_page($page);
	return $result;
}
